/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOLMETASCORE_H
#define BOLMETASCORE_H

#include <vector>
#include <iostream>
#include <assert.h>

#include <boost/shared_ptr.hpp>

#include "metascoredescriptor.h"


using namespace std;
namespace bol {


/**
  A vector of scores, with a default score() value
  This class is suppose to be a pure vurtual class, no?

  @author Alexandre Masselot,GeneBio,http://www.genebio.com, <alexandre.masselot@gmail.com>
 */
//@TODO implements score as sortable (inverse value of get score() function)
  class MetaScore{
    const MetaScoreDescriptor *m_descriptor;
    double *values;
    public:
    /**
     * instanciate a new MetaScore with a given (const!) descriptor
     * an array of values of the same size of descriptor is created
     * @param descriptor
     */
      MetaScore(MetaScoreDescriptor *descriptor):m_descriptor(descriptor){
        values=new double[descriptor->size()];
      }

      ~MetaScore(){
      }

      virtual double mainScore()const=0;

      const MetaScoreDescriptor* descriptor() const {
        return m_descriptor;
      }
      size_t size()const{
        return descriptor()->size();
      }
      /**
       * the comparison is done on the pure virtual score() function
       * @param s
       * @return
       */
      bool operator<(const MetaScore& s)const{
        assert(descriptor()==s.descriptor());
        return mainScore()<s.mainScore();
      }
      /**
       * the [] operator return a ref towrds the value, so it shuold be able to change the value
       * if the value is only meant to be read, see the below value(i)) method
       * @param i
       * @return the ith score value (no check is done on the possible array size range)
      */
      double& operator[](const size_t i){
        return values[i];
      }

      /**
       * set the i^th value of the metascore
       * @param i (<size(), although there is no check)
       * @param val 
       */
      void set(const size_t i, const double val){
        values[i]=val;
      }

      /**
       * get the ith value stored
       * @param i (<size(), although there is no check)
       * @return 
       */
      double value(const size_t i)const{
        return values[i];
      }
      static bool ltPtr(const MetaScore* s1, const MetaScore*s2){
        return s1->mainScore()<s2->mainScore();
      }

      friend ostream& operator<<(ostream& out, const MetaScore& score);
      friend istream& operator>>(istream& in, MetaScore& score);
  };
  typedef boost::shared_ptr<MetaScore> MetaScorePtr;


}

#endif
